﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.BLL;
using OgilvyOne.Model;

public partial class admin_infomation_article_comment_list : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            this.PopedomValidate(Request.Params["layerid"],QUERY);
            this.headers.Text = new ColumnBll().LayeridColumnConNaiv(layerid);
            showindex();
        }
    }
    //搜索按钮
    protected void Button1_Click(object sender, EventArgs e)
    {
        showindex();//查询条件读取包涵在此方法中
    }
    //删除按钮
    protected void Del_click(object sender, EventArgs e)
    {
        this.PopedomValidate(layerid, DEL);
        string idlist = GetSelIDlist();
        if (idlist.Trim().Length == 0)
        {
            return;
        }
        new ICmsArticleComments().DeleteComments(idlist);
        Response.Write("<script>alert('删除成功!')</script>");
        showindex();
    }
    //单个删除
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        this.PopedomValidate(layerid, DEL);
        ICmsArticleComments cac = new ICmsArticleComments();
        GridView gv = (GridView)sender;
        int cid = int.Parse(gv.DataKeys[e.RowIndex].Value.ToString());
        bool bo = cac.Delete(cid);
        if (bo == true)
        {
            Response.Write("<script>alert('删除成功!')</script>");
            insertLog("删除ID为：" +cid.ToString()+ "的评论"  );
            showindex();
        }
        else
        {
            Response.Write("<script>alert('删除失败!')</script>");
        }
    }
    //查看详情
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        GridView gv = (GridView)sender;
        string COMMENT_ID = gv.DataKeys[e.NewSelectedIndex].Value.ToString();
        Response.Redirect("article_comment_detail.aspx?COMMENT_ID=" + COMMENT_ID + "&layerid=" + Request.Params["layerid"]);
        return;
    }
    ////审核评论
    //protected void LinkButton3_Click(object sender, EventArgs e)
    //{
    //    this.PopedomValidate(Request.Params["layerid"], AUDIT);
    //    string aid = ((LinkButton)sender).CommandArgument;
    //    bool bo = new ICmsArticleComments().Audit(int.Parse(aid), 2, GetSessionUsersModel().Username);//GetSessionUsersModel().Username 获取当前管理员名称
    //    if (bo)
    //    {
    //        insertLog("审核" + new ICmsArticleComments().GetArticleCommentModel(int.Parse(aid)).MemberNickname + "的评论,评论ID为："+aid);
    //    }
    //    showindex();
    //}
    //评论发布
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        this.PopedomValidate(Request.Params["layerid"], PUB);
        string aid = ((LinkButton)sender).CommandArgument;
        bool bo = new ICmsArticleComments().Pubsh(int.Parse(aid), 1);
        if (bo)
        {
            insertLog("发布" + new ICmsArticleComments().GetArticleCommentModel(int.Parse(aid)).MemberNickname + "的评论,评论ID为：" + aid);
        }
        showindex();
    }
    //取消发布
    protected void LinkButton5_Click(object sender, EventArgs e)
    {
        this.PopedomValidate(Request.Params["layerid"], PUB);
        string aid = ((LinkButton)sender).CommandArgument;
        bool bo = new ICmsArticleComments().Pubsh(int.Parse(aid),0);
        new ICmsArticleComments().Audit(int.Parse(aid), 3, GetSessionUsersModel().Username);
        if (bo)
        {
            insertLog("取消" + new ICmsArticleComments().GetArticleCommentModel(int.Parse(aid)).MemberNickname + "的评论发布,评论ID为：" + aid);
        }
        showindex();
    }

    //第一页
    protected void btnFirst_Click1(object sender, EventArgs e)
    {
        this.GridView1.PageIndex = 0;
        showindex();
    }
    //上一页
    protected void btnPrev_Click(object sender, EventArgs e)
    {
        if (this.GridView1.PageIndex != 0)
        {
            this.GridView1.PageIndex = this.GridView1.PageIndex - 1;
            showindex();
        }
        else
        {
        }
    }
    //下一页
    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (this.GridView1.PageIndex != this.GridView1.PageCount - 1)
        {
            this.GridView1.PageIndex = this.GridView1.PageIndex + 1;
            showindex();
        }
        else
        {
        }
    }
    //最后一页
    protected void btnLast_Click(object sender, EventArgs e)
    {
        this.GridView1.PageIndex = this.GridView1.PageCount - 1;
        showindex();
    }
    //前往*页
    protected void btnGo_Click(object sender, EventArgs e)
    {
        try
        {
            int pa = int.Parse(this.txtNewPageIndex.Text.ToString());
            if (1 <= pa || pa <= this.GridView1.PageCount)
            {
                this.GridView1.PageIndex = pa - 1;
                showindex();
            }
            else
            {
                Response.Write("<script>alert('请输入正确的页码!')</script>");
                this.txtNewPageIndex.Text = (this.GridView1.PageIndex + 1).ToString();
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        CmsArticleCommentModel camm = new CmsArticleCommentModel();
        ICmsArticleComments cacb = new ICmsArticleComments();
        GridView1.DataSource = cacb.GetCommentList(camm);
        GridView1.DataBind();
    }
    //分页数据绑定显示
    protected void showindex()
    {
        CmsArticleCommentModel camm = new CmsArticleCommentModel();
        if (this.txtQueryname.Text.ToString().Trim() != null)
        {
            camm.CommentContent = this.txtQueryname.Text.ToString().Trim();
        }
        ICmsArticleComments cacb = new ICmsArticleComments();
        DataSet ds = cacb.GetCommentList(camm);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        int num = ds.Tables.Count;

        int index = this.GridView1.PageIndex + 1;
        int cont = this.GridView1.PageCount;
        this.label1.Text = "当前第" + index.ToString() + "页    共" + cont.ToString() + "页";
        this.label2.Text = "共" + num.ToString() + "条数据";
        this.txtNewPageIndex.Text = index.ToString();
        if (GridView1.Rows.Count == 0)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("COMMENT_ID");
            dt.Columns.Add("ARTICLE_ID");
            dt.Columns.Add("MEMBER_ID");
            dt.Columns.Add("COMMENT_TIME");
            dt.Columns.Add("STATE");
            dt.Columns.Add("AUDIT_STATE");
            dt.Columns.Add("AUDIT_TIME");
            dt.Rows.Add(dt.NewRow());
            GridView1.DataSource = dt;
            GridView1.DataBind();
            int columncount = dt.Columns.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
            GridView1.Rows[0].Cells[0].Text = "没有相关信息";
            GridView1.Rows[0].Cells[0].Style.Add("text-align", "center");
        }
        if (this.GridView1.PageCount != 1)
        {
            if (this.GridView1.PageIndex == 0)
            {
                btnFirst.Visible = false;
                btnPrev.Visible = false;
                btnNext.Visible = true;
                btnLast.Visible = true;
            }
            else if (this.GridView1.PageIndex == this.GridView1.PageCount - 1)
            {
                btnFirst.Visible = true;
                btnPrev.Visible = true;
                btnNext.Visible = false;
                btnLast.Visible = false;
            }
            else
            {
                btnFirst.Visible = true;
                btnPrev.Visible = true;
                btnNext.Visible = true;
                btnLast.Visible = true;
            }
        }
        else
        {
            btnFirst.Visible = false;
            btnPrev.Visible = false;
            btnNext.Visible = false;
            btnLast.Visible = false;
            btnGo.Visible = false;
            label1.Visible = false;
            label2.Visible = false;
            txtNewPageIndex.Visible = false;
            pages.Visible = false;
        }
    }
    //批量选择检查
    private string GetSelIDlist()
    {
        string idlist = "";
        bool BxsChkd = false;
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox checkbox = ((CheckBox)GridView1.Rows[i].FindControl("CheckBox1"));
            if (checkbox != null && checkbox.Checked == true)
            {
                BxsChkd = true;
                idlist += GridView1.Rows[i].Cells[1].Text.ToString() + ",";
            }
        }
        if (BxsChkd)
        {
            idlist = idlist.Substring(0, idlist.LastIndexOf(","));
        }
        return idlist;
    }
}
